/**
 * Copyright 2014 wasu.com
 *
 *
 * Create on 2015-5-17 下午11:05:02
 */
package xiaojian.toolkit.netty.util;

import xiaojian.toolkit.netty.handler.codec.http.request.HttpRequestExt;
import xiaojian.toolkit.util.MutablePropertyable;

/**
 * @author <a href="mailto:caoxiaojian@wasu.com>xiaojian.cao</a>
 * 
 */
public class NetUtils {

	/**
	 * 得到远程目标地址。
	 * 
	 * @param to
	 * @return
	 */
	public static final String getRemoteAddress(MutablePropertyable to) {
		String remoteAddr = null;
		HttpRequestExt httpRequestExt = (HttpRequestExt) to
				.getProperty("httpRequest");
		if (httpRequestExt != null) {

			remoteAddr = httpRequestExt.headers().get("RemoteIp");
			if (remoteAddr != null) {
				return remoteAddr;
			}

			remoteAddr = httpRequestExt.headers().get("X-Forwarded-For");
			if (remoteAddr != null) {
				return remoteAddr;
			}

			remoteAddr = httpRequestExt.headers().get("X-Real-IP");
		}

		return remoteAddr;
	}

}
